package com.blog.backend.controller;

import com.blog.backend.annotation.LoginAnno;
import com.blog.backend.model.BlogPlate;
import com.blog.backend.req.EditPlateReq;
import com.blog.backend.req.InsertPlateReq;
import com.blog.backend.req.PlateListReq;
import com.blog.backend.service.PlateService;
import com.blog.backend.utils.Result;
import com.blog.backend.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 技术板块接口
 * @author fanggs
 * @Date 2021/7/14 0014 9:52
 */
@RestController
@Api(tags = "技术板块功能接口")
public class PlateController {

    @Resource
    private PlateService plateService;

    @PostMapping("/plate/increasePlate")
    @LoginAnno
    @ApiOperation("新增板块分类")
    public Result<Boolean> insertPlate(@RequestBody InsertPlateReq req){
      Boolean flag= plateService.insertPlate(req);
       return Result.success(flag);
    }

    @PostMapping("/plate/plateList")
    @LoginAnno
    @ApiOperation("板块分类列表查询")
    public Result<PageResult> selectList(@RequestBody PlateListReq req){
        PageResult list =  plateService.selectList(req);
        return Result.success(list);
    }

    @GetMapping("/plate/detail")
    @LoginAnno
    @ApiOperation("查看板块详情")
    public Result<BlogPlate> queryDetail(@RequestParam("plateId")String plateId){
        BlogPlate plate = plateService.queryDetail(plateId);
        return Result.success(plate);
    }

    @PostMapping("/plate/editDetail")
    @LoginAnno
    @ApiOperation("修改板块内容")
    public Result<Integer> editDetail(@RequestBody EditPlateReq req){
        Integer result=plateService.editDetail(req);
       return Result.success(result);
    }

    @GetMapping("/plate/deletePlate")
    @LoginAnno
    @ApiOperation("删除板块")
    public Result<Integer> deletePlate(@RequestParam("plateId")String plateId){
        Integer result=plateService.deletePlate(plateId);
        return Result.success(result);
    }
}
